package com.raycloud.dingtalk.starter.handle;

import org.apache.commons.cli.Option;

import java.util.HashMap;
import java.util.Map;

/**
 * 通用行为抽象
 */
public abstract class AbstractMapOptionCommandHandle implements CommandHandle {
    @Override
    public String handle(Option[] options) {
        Map<String, Option> optionMap = new HashMap<>(options.length << 1);
        for (Option option : options) {
            optionMap.put(option.getOpt(), option);
            optionMap.put(option.getLongOpt(), option);
        }
        Option help = optionMap.get("h");
        if (help != null) {
            return help.getDescription();
        }
        return handle(optionMap);
    }

    public abstract String handle(Map<String, Option> optionMap);
}
